<template>
  <el-dialog title="新增区段" :modelValue="visiable" width="50%" @close="emit('closed')">
    <el-form :model="model" label-width="80px" :inline="false" v-if="model">
      <!-- 名称 -->
      <el-form-item label="名称">
        <el-input v-model="model.name">
          <template #suffix>
            <ApplicationOne theme="outline" size="18" fill="#888" />
          </template>
        </el-input>
      </el-form-item>

      <!-- 文件选择 -->
      <el-form-item label="文件选择">
        <el-input placeholder="选择文件">
          <template #append>
            <el-button>
              <FolderOpen theme="outline" size="16" fill="#888" />
            </el-button>
          </template>
        </el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button @click="cancel">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script setup lang="ts">
import useSection from '@/composables/useSection'
import { ApplicationOne, FolderOpen } from '@icon-park/vue-next'
import { reactive } from 'vue'

const prop = defineProps<{
  visiable: boolean
  projId: number
}>()
const emit = defineEmits(['closed'])
const { add } = useSection()

const model = reactive({
  name: '',
})

async function onSubmit() {
  await add({
    ...model,
    projId: prop.projId,
  })
  emit('closed')
}

// 取消
function cancel() {
  emit('closed')
}
</script>

<style></style>
